package lesson1;

public class MainApp {
    // public - access modifier - encapsulation; optional for class definition
    // class - define a type; (class | abstract class | interface | enum)
    // --- variables - data holder
    // --- functions - method
    
    /**
     * main method
     */
    public static void main(String[] args){
        
        // public - access modifier (public, protected, private, <default>)
        // static - define containtment of either variables or functions
        // void - specifies the return type
        // main - function name
        // {} - specify parameter list; (String[] args) - single argument param list
        // String - a type in java; Reference types and primitives
        // [] - array
        // args - variable name
        
        System.out.println("Hello World");
        // Array Syntax - 2 ways to declare:
        // - String [] args
        // - String args []
        // - implicit variable - length - describes the capacity
        System.out.println("Length of args array: " + args.length);
        
//        for(int x=0; x < args.length; x++){
//            
//            System.out.println("element[" + x + "]: " + args[x]);
//        }
        System.out.println("");
        if(args.length == 0){
            System.out.println("No arguments were specified.");
        }
        else if(args.length > 3 && args.length < 5){
            // do something else
            System.out.println("Args is 4");
        }
        else if(args.length > 6){
            // do something else else
            System.out.println("Args > 6");
        }
        else{
            System.out.println("Args is 1 or 2");
            printArgs(args);
            sumArgs(args);
        }
//        int x=0;
//        while(x < args.length){
//            System.out.println("element[" + x + "]: " + args[x]);
//            x++;
//        }
        
    }
    
    public static void printArgs(String[] args){
        int count = 0;
        for(String s : args){
            System.out.println("element["+count+"]: " + s);
            count++;
        }
    }

    private static void sumArgs(String[] args) {
        int sum = 0;
        for(int i=0; i < args.length; i++){
            try{
                sum = sum + Integer.parseInt(args[i]);
            }
            catch(NumberFormatException e){
                
            }
        }
        System.out.println("Sum of args = " + sum);
    }
}